package com.takeshi.landlords.entity;

import com.takeshi.landlords.config.Dealer;
import io.netty.channel.ChannelId;
import io.netty.util.concurrent.ScheduledFuture;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * GamePlayer
 *
 * @author Nanase Takeshi
 * @date 2022/2/18 14:56
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class GamePlayer {

    /**
     * 通道ID
     */
    private ChannelId channelId;
    /**
     * 用户名
     */
    private String nickname;
    /**
     * 房间号
     */
    private Integer roomNumber;
    /**
     * 当前用户所在界面
     */
    private Integer state;
    /**
     * 用户手里的牌
     */
    private List<String> handCardList;

    /**
     * 倒计时时间
     */
    private AtomicInteger countdown;

    /**
     * 用户的出牌超时任务
     */
    private ScheduledFuture<?> scheduledFuture;

    /**
     * 成为地主，将底牌放入地主手牌中
     *
     * @param holeCard
     */
    public void becomeLandlord(List<String> holeCard) {
        this.handCardList.addAll(holeCard);
        this.handCardList.sort(Comparator.comparing(Dealer.SHOW_FULL_POKER_ORDER::indexOf));
    }

    public void gameOver() {
        this.handCardList = null;
    }

}
